﻿@model Jb.Web.ViewModels.JobSeekerViewModel
@using Jb.Web.Utility;
@using Jb.Common.Extensions;

@{
    String pageTitle = "Edit Profile";
    if (Model != null && Model.ID == 0)
    {
        pageTitle = "Add New JobSeeker";
    }
    ViewBag.Title = Html.GetPageTitle(pageTitle);
    ///Set Selected Left Menu
    ViewData[AppConstants.ViewDataKeys.SELECTED_MENU] = JobSeekerMenu.Profile;
    bool _HasSaved = ViewData[AppConstants.ViewDataKeys.SAVED] == null ? false : Jb.Common.DB.NullHandler.GetBoolean(ViewData[AppConstants.ViewDataKeys.SAVED]);
}

<div class="jb-page-heading">
    <h1>@pageTitle</h1>
    <div>Enter necessary information and then click the Save button.</div>
</div>
<div class="jb-page-content">
@using (Html.BeginForm())
{
    @Html.ValidationSummary(false)

    if (Model == null)
    {
        @: @Html.WarningMessageBox("Sorry! Requested JobSeeker was not found for edit.")
    }
    else
    {
        if (Model.Name == AppConstants.ValueOf.UNKNOWN){
            Model.Name = String.Empty;
        }
        
        if (_HasSaved) {
            @Html.SuccessMessageBox("Congratulations! your profile saved successfully");
        }
        else if (ViewData[AppConstants.ViewDataKeys.SAVED] != null && !_HasSaved) {
            @Html.WarningMessageBox("Sorry! we could not save your profile information.")
        }        
		@Html.HiddenFor(model => model.ID)        
		<div class="editor-label">
			@Html.LabelFor(model => model.Name)
		</div>
		<div class="editor-field">
			@Html.TextBoxFor(model => model.Name)
			@Html.ValidationMessageFor(model => model.Name)
		</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.Gender)
		</div>
		<div class="editor-field jb-inline-label">
            @Html.RadioButtonFor(model => model.Gender, "M", new { id = "rdnGender_M" }) <label for="rdnGender_M">Male</label>
            @Html.RadioButtonFor(model => model.Gender, "F", new { id = "rdnGender_F" }) <label for="rdnGender_F">Female</label>		
			@Html.ValidationMessageFor(model => model.Gender)
		</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.DateOfBirth)
		</div>
		<div class="editor-field">
			@Html.TextBoxFor(model => model.DateOfBirth, new { @class = "datepicker" })
			@Html.ValidationMessageFor(model => model.DateOfBirth)
		</div>
    
        String logoUrl = ImageManager.GetJobSeekerPhotoUrl(Model.PhotoFile, Model.ID);
        //String jsOnClick = String.Format("ShowCenteredPopUp('{0}', 'UploadImage', 1152, 600, true);", Url.Action("List", "CompanyLogo", new { ID = Model.ID }));
        String jsOnClick = "ShowPhotoEditDialog();";
        String altText = Model.PhotoFile.IsNullOrEmpty() ? "Add New Photo" : "Change your photo";
		
		<div class="editor-field">
            @Html.HiddenFor(model => model.PhotoFile)            
            <a href="javascript:void(0);" onclick="@jsOnClick">Manage Profile Photo</a>
            <ul class="thumbnails">
                <li class="span4__" style="width:auto; margin:5px 0px 0px 0px;">
                    <a href="javascript:void(0);" class="thumbnail" onclick="@jsOnClick">
                        <img id="imgJobSeekerPhoto" src="@logoUrl" alt="@altText" title="@altText" />
                    </a>
                </li>
            </ul>
		</div>
    
        @Html.HiddenFor(model => model.AddressID)
        <div class="jb-group-title">
            <a href="javascript:void(0);" data-toggle="collapse" data-target="#divAddress">
                <i id="iAddressToggle" class="icon-minus-sign"></i>Address Information
            </a>
        </div>
        <div id="divAddress" class="collapse in">
        @Html.EditorFor(model => model.Address)
        </div>
    
        @Html.HiddenFor(model => model.HasProfileCompleted)

        <!--Modal Popup Section Start-->
        <div id="divPhotoEditModal">
            <iframe id="iframeImageList" scrolling="no" frameborder="0" src=""></iframe>
        </div>
        <!--Modal Popup Section End-->
    
	    <div class="jb-button-container">
			<button type="submit" class="btn btn-primary"><i class="icon-hdd icon-white"></i> Save</button>
            <a href="@Url.PrivateUrl("Dashboard", "Account")" class="btn">Cancel</a>            
		</div>		
    }
}
</div>

@section PageHeadSection
{
    <link href="@Url.Content("~/Content/themes/jb-ui/jquery.ui.all.css")" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .ui-corner-all, .ui-corner-bottom, .ui-corner-left, .ui-corner-bl {border-bottom-left-radius: 0px;}
        .ui-corner-all, .ui-corner-bottom, .ui-corner-right, .ui-corner-br { border-bottom-right-radius: 0px;}
        #divPhotoEditModal{width:990px; height:560px; padding:0px;}
        #iframeImageList{width:100%;}
    </style>    
}
@section JavaScriptPlaceHolder
{
@Html.JavaScript("jquery.validate.min.js", Url)
@Html.JavaScript("jquery.validate.unobtrusive.min.js", Url)
@Html.JavaScript("jquery-ui-1.8.11.min.js", Url)
@Html.Partial("_DatePicker")

<script language="javascript" type="text/javascript">
    var _PhotoDialog = null;
    $(document).ready(function () {
        _PhotoDialog = $('#divPhotoEditModal').dialog({
            autoOpen: false,
            title: 'Manage Profile Photo',
            modal: true,
            width: $('#divPhotoEditModal').width(),
            height: $('#divPhotoEditModal').height()
        });
        $('#divAddress').on('show', function () { $('#iAddressToggle').removeClass('icon-plus-sign').addClass('icon-minus-sign'); })
                        .on('hide', function () { $('#iAddressToggle').removeClass('icon-minus-sign').addClass('icon-plus-sign'); });
    });
    function AdjustiFrameHeight(height) {
        $('#iframeImageList').height(height);
    }
    function ChildHideLoading() {
        HideLoadingAnimation();
    }
    function SetLogo(logoUrl) {
        $('#imgJobSeekerPhoto').attr('src', logoUrl);
        var parts = logoUrl.split('/');
        $('#PhotoFile').val(parts[parts.length - 1]);
    }
    function ShowPhotoEditDialog() {
        $(_PhotoDialog).dialog('open');
        var iFrame = $(_PhotoDialog).find('iframe');
        if ($(iFrame).attr('src').length == 0) {
            $(iFrame).attr('src', '@Url.JobSeekerUrl("PhotoList/" + Model.ID, "Home")');
            ShowLoadingAnimation(false);
        }
    }   
</script>
}

